#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/5/27 17:18
# @Author  : khz_df
# @Site    : 
# @File    : foo_mnist.py
# @Software: ce9nt
"""
https://www.bilibili.com/video/av18091678/?spm_id_from=trigger_reload
"""


import os
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('model', one_hot=True)

learning_rate = 0.01    # 学习速率
batch_size = 128        # 每次训练数据量
n_epochs = 30           # 一共训练了多少次

import tensorflow as tf
X = tf.placeholder(tf.float32, [batch_size, 784])
Y = tf.placeholder(tf.int32, [batch_size, 10])


def main():
    with tf.name_scope("Wx_b") as scope:
        w = tf.Variable(tf.random_normal(shape=[784, 10], stddev=0.01), name='weights')
        b = tf.Variable(tf.zeros([1, 10]), name='bias')
        logits = tf.matmul(X, w) + b

    with tf.name_scope('cost') as scope:
        entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y, name='loss')
        loss = tf.reduce_mean(entropy)       # 计算误差的平均值
        tf.summary.scalar('loss', loss)

    with tf.name_scope('train') as scope:
        optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)

    summary = tf.summary.merge_all()


if __name__ == "__main__":
    print("------------------    Enter __main__    ------------------")

    print(u"[Current work directory is : ]\t" + os.getcwd())
    print(u"[Current process ID is : ]\t" + str(os.getpid()))
    print("\n")
    main()

    print("------------------    Leave __main__    ------------------")
